#lang racket


(provide (struct-out interval)
         make-interval)

(define (interval-print interval port mode)
  (if (eq? (interval-min-s interval) 'open)
      (write-string "]" port)
      (write-string "[" port))
  (write-string (format "~a" (interval-min-val interval)) port)
  (write-string " " port)
  (write-string (format "~a" (interval-max-val interval)) port)
  (if (eq? (interval-max-s interval) 'open)
      (write-string "[" port)
      (write-string "]" port)))

(define-struct interval
  (min-s min-val max-s max-val)
  #:constructor-name new-interval
  #:property prop:custom-write interval-print)

(define (make-interval min-s min-val max-s max-val)
  (when (> min-val max-val)
    (error 'make-interval "Min val is greater than max val"))
  (new-interval min-s min-val max-s max-val))